local skel = fk.CreateSkill {
  name = "emo__ningyuan",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__ningyuan"] = "凝渊",
  [":emo__ningyuan"] = "锁定技，游戏开始时，你令一名其他角色获得〖骇型〗。你每回合首次对其他角色造成伤害后，若其没有〖骇型〗，其获得之；若已有，其手牌上限-1。",

  ["#emo__ningyuan-choose"] = "韶光：你令一名其他角色获得〖骇型〗",
  ["#emo__ningyuan-exchange"] = "韶光：你可以用任意张手牌替换等量的“韶光”",
}

skel:addEffect(fk.GameStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:hasSkill("emo__haixing", true) end)
    if #targets == 0 then return false end
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__ningyuan-choose",
    })
    if #tos > 0 then
      room:handleAddLoseSkills(tos[1], "emo__haixing")
    end
  end,
})

skel:addEffect(fk.Damage, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and data.to ~= player and not data.to.dead then
      local first = player.room.logic:getActualDamageEvents(1, function (e)
        local dmg = e.data
        return dmg.from == player and dmg.to ~= player
      end, Player.HistoryTurn)[1]
      return first and first.data == data
    end
  end,
  on_cost = function (self, event, target, player, data)
    event:setCostData(self, { tos = { data.to } })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    if not to:hasSkill("emo__haixing", true) then
      room:handleAddLoseSkills(to, "emo__haixing")
    else
      room:addPlayerMark(to, MarkEnum.MinusMaxCards)
    end
  end,
})

return skel
